﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PromotionApp.Model;
using PromotionApp.DAL;
using System.Data;

namespace PromotionApp.Utility
{
    public static class DynamicQueryHelper
    {
        public static string GetConditionPrefix(ref bool blnCondition)
        {
            string strPrefix = "AND";

            if (!blnCondition)
            {
                strPrefix = "WHERE";
                blnCondition = true;
            }

            return strPrefix;
        }

        public static string GetStartNo(int pageSize, int pageNumber)
        {
            int startRow = (pageSize * (pageNumber - 1)) + 1;

            return startRow.ToString();
        }

        public static string GetEndNo(int pageSize, int pageNumber)
        {
            int endRow = pageSize * pageNumber;

            return endRow.ToString();
        }

        public static void GetMaxPageNumber(string strCountQuery, BasePagingArgs e)
        {            
            int remain = e.Total % e.PageSize;

            e.MaxPageNumber = e.Total / e.PageSize;

            if (remain > 0)
                e.MaxPageNumber += 1;
        }
    }
}